package com.mes.schedule.manager.iface;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.jdom2.Element;

import com.mes.common.exception.bo.BaseBusinessException;
import com.mes.common.manager.iface.IBasicManager;
import com.mes.common.util.IdentityGenerator;
import com.mes.common.util.Page;
import com.mes.schedule.domain.SOperationTask;
import com.mes.schedule.domain.SPartTask;
import com.mes.schedule.domain.ScheduleEvent;
import com.mes.schedule.domain.ScheduleOperationRecord;
import com.mes.schedule.domain.ScheduleScheme;

/**
 * <p>
 * 调度事件管理
 * </p>
 * Created on Mar 11, 2008
 * 
 * @author lhy
 * 
 */
public interface IScheduleOperationRecordManager extends IBasicManager {

	/**
	 * 按照事件sourceuid来决定是新增或者更改事件，避免同类事件重复发送
	 * 
	 * @param masterShopUid
	 *            产生事件的部门
	 * @param scheduleEvent
	 * @throws BaseBusinessException
	 */
	public void SaveOrUpdateBySource(String masterShopUid,
			ScheduleEvent scheduleEvent) throws BaseBusinessException;

	/**
	 * 按照事件sourceuid来决定是新增或者更改事件，避免同类事件重复发送
	 * 
	 * @param masterShopUid
	 *            产生事件的部门
	 * @param scheduleEvent
	 * @throws BaseBusinessException
	 * @throws Exception 
	 */
	public void addScheduleEvent(String masterShopUid,
			ScheduleEvent scheduleEvent) throws BaseBusinessException, Exception;

	public void writeOperLog(ScheduleScheme scheme, String eventType,
			Element operElement) throws Exception;

	/**
	 * 获取事件的主参数 by hba
	 * 
	 * @param scheduleEvent
	 * @param eventPara
	 * @param scheme
	 * @return
	 * @throws Exception
	 */
	public String getEventPara(ScheduleEvent scheduleEvent, String eventPara,
			ScheduleScheme scheme) throws Exception;

	/**
	 * 获取事件的子参数 by hba
	 * 
	 * @param scheduleEvent
	 * @param eventPara
	 * @param scheme
	 * @return
	 */
	public List<String> getEventChildPara(ScheduleEvent scheduleEvent,
			String eventPara, ScheduleScheme scheme) throws Exception;

	public List<ScheduleOperationRecord> findScheduleEventsByConditions(
			ScheduleScheme scheme, String keyUid, Date fromDate, Date toDate,
			Integer eventState, String eventType, String eventObject,
			String drawingId, String batchNum, Page page) throws Exception;

	public void createSplitBatchInfo(List<SPartTask> updatedPartList,
			List<SOperationTask> splitedOperationsList, String parentUid);

	/**
	 * 根据操作记录生成XML格式
	 * 
	 * @param record
	 * @param scheme
	 * @return
	 */
	public Element createElementFormat(ScheduleOperationRecord record,
			Map<String, SPartTask> allPartTaskMap,
			Map<String, SOperationTask> allOperationTaskMap);

	/**
	 * 将基准方案的操作拷贝到新方案下 by hba
	 * 
	 * @param scheduleScheme
	 * @throws Exception 
	 */
	public void copyOperationRecord(ScheduleScheme scheduleScheme) throws Exception;

	public void writeOperationPartTaskLog(ScheduleScheme scheme,
			SPartTask oldPartTask, SPartTask partTask, String eventType) throws Exception;

	public void writeCombineBatchLog(ScheduleScheme scheme,
			List<SPartTask> combineBatchList) throws Exception;

	public void writeSplitBatchLog(ScheduleScheme scheme, SPartTask partTask,
			List<SOperationTask> splitedBatchs) throws Exception;

	public void writeOperOperationLog(ScheduleScheme scheme,
			SOperationTask oldOpTask, SOperationTask newOpTask, String eventType) throws Exception;

	public void writeGroupTasksLog(ScheduleScheme scheme,
			List<SOperationTask> taskList) throws Exception;

	public void writeCancelSplitBatchLog(ScheduleScheme scheme,
			SPartTask partTask, List<SPartTask> splitedBatchs) throws Exception;

	public void writeCancelCombineBatchLog(ScheduleScheme scheme,
			SPartTask partTask) throws Exception;

	public void writeCancelGroupTasksLog(ScheduleScheme scheme,
			SOperationTask groupTask) throws Exception;

}
